package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RcTemplate;
import com.ruoyi.system.service.IRcTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 内容Controller
 *
 * @author ruoyi
 * @date 2023-07-27
 */
@RestController
@RequestMapping("/basic/temp")
public class RcTemplateController extends BaseController
{
    @Autowired
    private IRcTemplateService rcTemplateService;

    /**
     * 查询内容列表
     */
    //@PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(RcTemplate rcTemplate)
    {
        startPage();
        List<RcTemplate> list = rcTemplateService.selectRcTemplateList(rcTemplate);
        return getDataTable(list);
    }

    /**
     * 导出内容列表
     */
    //@PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RcTemplate rcTemplate)
    {
        List<RcTemplate> list = rcTemplateService.selectRcTemplateList(rcTemplate);
        ExcelUtil<RcTemplate> util = new ExcelUtil<RcTemplate>(RcTemplate.class);
        util.exportExcel(response, list, "内容数据");
    }

    /**
     * 获取内容详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rcTemplateService.selectRcTemplateById(id));
    }

    /**
     * 新增内容
     */
    //@PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RcTemplate rcTemplate)
    {
        rcTemplate.setCreateBy(getUsername());
        return toAjax(rcTemplateService.insertRcTemplate(rcTemplate));
    }

    /**
     * 修改内容
     */
    //@PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RcTemplate rcTemplate)
    {
        rcTemplate.setUpdateBy(getUsername());
        return toAjax(rcTemplateService.updateRcTemplate(rcTemplate));
    }

    /**
     * 删除内容
     */
    //@PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rcTemplateService.deleteRcTemplateByIds(ids));
    }
}
